ERDEV, ERDEV$ Functions ---------------------------------------------------------------------------- Action Provide device-specific status information after an error. Syntax ERDEV ERDEV$ Remarks ERDEV is an integer function that returns an error code from the last device that generated a critical error. ERDEV$ is a string function that returns the name of the device that generated the error. Because ERDEV and ERDEV$ return meaningful information only after an error, they usually are used in error-handling routines specified by an ON ERROR statement. ERDEV$ contains the 8-byte character device name if the error is on a character device, such as a printer, or the 2-byte block name (A., B., etc.) if the device is not a character device. It contains the 3-byte block name (COM) if the communications port experiences a timeout. ERDEV is set by the critical error handler (interrupt 24H) when DOS detects a critical DOS call error. It also is set by a timeout error on the communications port and indicates which option in the OPEN COM statement (CD, CS, or DS) is experiencing the timeout. ERDEV returns an integer value that contains information about the error. For block and character device errors, the low byte of ERDEV contains the DOS error code. For block devices only, the high byte contains device-attribute information. For COM timeout errors, ERDEV returns a value corresponding to the source of the timeout. For more information, see the entry for the OPEN COM statement. Assuming an ERDEV return value of x, the following program lines generate the DOS error code (low byte) and device attribute information (high byte). DosErrCode = x AND &HFF' Low byte of ERDEV. DevAttr = (x AND &HFF00) \ 256 ' High byte of ERDEV. For more information about device-attribute words, see the Microsoft MS-DOS Programmer's Reference, or books such as The Peter Norton Guide to the IBM PC or Advanced MS-DOS. Use ERDEV only in DOS. Example The following example prints the values of ERDEV and ERDEV$ after the program generates an error attempting to open a file. DEFINT A-Z ON ERROR GOTO ErrorHandler' Indicate first line of error handler. OPEN "A.JUNK.DAT" FOR INPUT AS #1' Attempt to open the file. END ErrorHandler. PRINT "ERDEV value is "; ERDEV PRINT "Device name is "; ERDEV$ ON ERROR GOTO 0 Output Running the program with drive A unlatched produces the following output (2 i ERDEV value is 2 Device name is A.